<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/7 0007
 * Time: 下午 5:07
 */
namespace app\api\controller;



use app\admin\model\AppManage;
use app\common\service\MiniProgramHelp;
use app\common\validate\WechatAuth;
use think\Db;
use think\Request;

class WechatOpenApi{

    public function getOpenAppID(){
        return config('miniprogram.MiaoDaoOpenAppID');
    }

    public function getCompomentAccessToken(){
        return MiniProgramHelp::getCompomentAccessToken();
    }

    public function getWechatLoginUrl(){
        return config('miniprogram.login_url');
    }

    /**
     * 添加微信小程序体验者
     * @return mixed|void
     */
    public function addexperiencer(){
        $param = Request::instance()->param();
        $wechatid = $param['wechatid'];
        $AppManage = AppManage::where('projectId',$param['b'])->find();
        if($AppManage){
            $res = MiniProgramHelp::AddWechatExperiencer($AppManage->id,$wechatid);
            return $res;
        }

    }

    //获取授权方的帐号基本信息
    public function getAuthorizerInfo(Request $request){
        $businessId = $request->param()['b'];
        return MiniProgramHelp::getAuthorizerInfo($businessId);
    }

    public function getAuthorizerToken(Request $request){
        $businessId = $request->param()['b'];
        $isRefresh = (bool)$request->param()['isRefresh'];
        $AppManage = AppManage::where('projectId',$businessId)->find();
        return MiniProgramHelp::getAuthorizerToken($AppManage->id,$isRefresh);
    }

    public function getAuditStatus(Request $request){
        $businessId = $request->param()['b'];
        $AppManage = AppManage::where('projectId',$businessId)->find();
        return MiniProgramHelp::getAuditStatus($AppManage->id);
    }

    //获取小程序体验二维码
    public function showqrcode(Request $request){
        $businessId = $request->param()['b'];
        $AppManage = AppManage::where('projectId',$businessId)->find();
        return MiniProgramHelp::getQrcode($AppManage->id);
    }

    //获取模板库最新模板
    public function getTemplateList(){
        return MiniProgramHelp::getTemplateList();
    }

    //修改服务器地址
    public function modifyDomain(Request $request){
        $businessId = $request->param()['b'];
        $projectType = $request->param()['projectType'];
        $AppManage = AppManage::where('projectId',$businessId)->find();
        return MiniProgramHelp::modifyDomain($AppManage->id,$projectType);
    }

    //提交代码

    public function commitCode(Request $request){
        $businessId = $request->param()['b'];
        $templateId = $request->param()['template_id'];
        $user_version = $request->param()['user_version'];
        $user_desc = $request->param()['user_desc'];
        $AppManage = AppManage::where('projectId',$businessId)->find();
        return MiniProgramHelp::commitCode($AppManage->id,$templateId,$user_version,$user_desc);
    }

    //提交审核

    public function submitAuditCode(Request $request){
        $businessId = $request->param()['b'];
        $tag['tag'] = $request->param()['posttag'];
        $AppManage = AppManage::where('projectId',$businessId)->find();

        return MiniProgramHelp::submitAuditCode($AppManage->id,$tag);
    }

    //发布代码

    public function releaseCode(Request $request){
        $AppManageId = $request->param()['b'];
        return MiniProgramHelp::releaseCode($AppManageId);
    }

}